From 45cff73426a0b75fa67bddf6f6b21aed5176e1f0 Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Fri, 10 Jan 2020 13:47:24 -0700 Subject: [PATCH] Cetcleanup (#454) * remove some obsolete cet code. * chip away at cet a bit more. * repair GDB_DEBUG, eliminating cet usage. --- cet_util.cc | 60 ++++++++++----------------------- cet_util.h | 4 +-- defs.h | 1 - gdb.cc | 97 ++++++++++++++++------------------------------------- main.cc | 10 +++--- route.cc | 1 - 6 files changed, 53 insertions(+), 120 deletions(-) diff --git a/cet_util.cc b/cet_util.cc index 6b5666b9d..6385d2e5b 100644 --- a/cet_util.cc +++ b/cet_util.cc @@ -19,13 +19,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include // for printf, snprintf +#include // for qsort + +#include // for QByteArray +#include // for QDebug +#include // for QTextCodec + #include "defs.h" -#include "cet.h" +#include "cet.h" // for cet_cs_vec_t, cet_str_any_to_utf8, cet_str_utf8_to_any, cet_str_any_to_uni #include "cet_util.h" -#include "src/core/logging.h" -#include -#include -#include // qsort +#include "src/core/logging.h" // for Fatal + #define MYNAME "cet_util" @@ -43,9 +48,9 @@ static int cet_output = 0; /* %%% fixed inbuild character sets %%% */ -#include "cet/ansi_x3_4_1968.h" -#include "cet/cp1252.h" -#include "cet/iso_8859_8.h" +#include "cet/ansi_x3_4_1968.h" // for cet_cs_vec_ansi_x3_4_1968, cet_cs_name_ansi_x3_4_1968 +#include "cet/cp1252.h" // for cet_cs_name_cp1252, cet_cs_vec_cp1252 +#include "cet/iso_8859_8.h" // for cet_cs_name_iso_8859_8, cet_cs_vec_iso_8859_8 /* %%% short hand strings transmission for main character sets %%% */ @@ -312,18 +317,12 @@ cet_flag_waypt(const Waypoint* wpt) (const_cast(wpt))->wpt_flags.cet_converted = 1; } -static void -cet_flag_route(const route_head* rte) -{ - (const_cast(rte))->cet_converted = 1; -} - static void cet_flag_all() { waypt_disp_all(cet_flag_waypt); - route_disp_all(cet_flag_route, nullptr, cet_flag_waypt); - track_disp_all(cet_flag_route, nullptr, cet_flag_waypt); + route_disp_all(nullptr, nullptr, cet_flag_waypt); + track_disp_all(nullptr, nullptr, cet_flag_waypt); } /* -------------------------------------------------------------------- */ @@ -393,28 +392,6 @@ cet_convert_waypt(const Waypoint* wpt) } } -/* cet_convert_route_hdr: internal used within cet_convert_strings process */ - -static void -cet_convert_route_hdr(const route_head* route) -{ - auto* rte = const_cast(route); - - if ((cet_output == 0) && (rte->cet_converted != 0)) { - return; - } - - rte->cet_converted = 1; -} - -/* cet_convert_route_tlr: internal used within cet_convert_strings process */ - -static void -cet_convert_route_tlr(const route_head* route) -{ - (void)route; -} - /* %%% cet_convert_strings (public) %%% * * - Convert all well known strings of GPS data from or to UTF-8 - @@ -422,10 +399,9 @@ cet_convert_route_tlr(const route_head* route) * !!! One of "source" or "target" must be internal cet_cs_vec_utf8 or NULL !!! */ void -cet_convert_strings(const cet_cs_vec_t* source, const cet_cs_vec_t* target, const char* format) +cet_convert_strings(const cet_cs_vec_t* source, const cet_cs_vec_t* target) { const char* cs_name_from, *cs_name_to; - (void)format; converter = nullptr; @@ -457,8 +433,8 @@ cet_convert_strings(const cet_cs_vec_t* source, const cet_cs_vec_t* target, cons } waypt_disp_all(cet_convert_waypt); - route_disp_all(cet_convert_route_hdr, cet_convert_route_tlr, cet_convert_waypt); - track_disp_all(cet_convert_route_hdr, cet_convert_route_tlr, cet_convert_waypt); + route_disp_all(nullptr, nullptr, cet_convert_waypt); + track_disp_all(nullptr, nullptr, cet_convert_waypt); cet_output = 0; diff --git a/cet_util.h b/cet_util.h index f82725471..4214413bc 100644 --- a/cet_util.h +++ b/cet_util.h @@ -45,7 +45,7 @@ extern cet_cs_vec_t cet_cs_vec_utf8; /* helpers */ -char* cet_str_any_to_any(const char* src, const cet_cs_vec_t* src_vec, const cet_cs_vec_t* dest_vec); +[[deprecated]] char* cet_str_any_to_any(const char* src, const cet_cs_vec_t* src_vec, const cet_cs_vec_t* dest_vec); /* cet_convert_string: !!! ONLY VALID WITHIN 'cet_convert_strings' process !!! */ char* cet_convert_string(char* str); @@ -54,7 +54,7 @@ const char* cet_convert_string(const QString& str); /* gpsbabel extensions */ void cet_convert_init(const QString& cs_name, int force); -void cet_convert_strings(const cet_cs_vec_t* source, const cet_cs_vec_t* target, const char* format); +void cet_convert_strings(const cet_cs_vec_t* source, const cet_cs_vec_t* target); void cet_convert_deinit(); #endif // CET_UTIL_H_INCLUDED_ diff --git a/defs.h b/defs.h index 1f0a995a0..d28e27357 100644 --- a/defs.h +++ b/defs.h @@ -710,7 +710,6 @@ public: int rte_num; int rte_waypt_ct; /* # waypoints in waypoint list */ format_specific_data* fs; - unsigned short cet_converted; /* strings are converted to UTF8; interesting only for input */ gb_color line_color; /* Optional line color for rendering */ int line_width; /* in pixels (sigh). < 0 is unknown. */ const session_t* session; /* pointer to a session struct */ diff --git a/gdb.cc b/gdb.cc index 8d6c01fce..85474387b 100644 --- a/gdb.cc +++ b/gdb.cc @@ -31,6 +31,7 @@ #include // for QByteArray #include // for QList #include // for QString, operator!=, operator== +#include // for QVector #include // for CaseInsensitive #include // for qPrintable, Q_UNUSED, foreach @@ -201,39 +202,6 @@ static QString fread_cstr() return rv; } -#if GDB_DEBUG -static char* -nice(const char* str) -{ - char* res, *env; - cet_cs_vec_t* vec; - - if (!(str && *str)) { - return ""; - } - - env = getenv("LANG"); - if (env == NULL) { - return (char*)str; - } - - if ((res = strchr(env, '.'))) { - env = ++res; - } - vec = cet_find_cs_by_name(env); - - if ((vec != NULL) && (vec != global_opts.charset)) { - static char buf[128]; - res = cet_str_any_to_any(str, global_opts.charset, vec); - strncpy(buf, res, sizeof(buf)); - xfree(res); - return buf; - } else { - return (char*)str; - } -} -#endif - static char* gdb_fread_cstr(gbfile* fin) { @@ -463,9 +431,6 @@ read_waypoint(gt_waypt_classes_e* waypt_class_out) char* str; #ifdef GMSD_EXPERIMENTAL char subclass[22]; -#endif -#if GDB_DEBUG - char* sn; #endif waypt_ct++; res = new Waypoint; @@ -473,9 +438,6 @@ read_waypoint(gt_waypt_classes_e* waypt_class_out) gmsd = garmin_fs_alloc(-1); fs_chain_add(&res->fs, (format_specific_data*) gmsd); res->shortname = fread_cstr(); -#if GDB_DEBUG - sn = xstrdup(nice(res->shortname)); -#endif wpt_class = (gt_waypt_classes_e) FREAD_i32; GMSD_SET(wpt_class, wpt_class); if (wpt_class != 0) { @@ -504,39 +466,37 @@ read_waypoint(gt_waypt_classes_e* waypt_class_out) #if GDB_DEBUG DBG(GDB_DBG_WPTe, 1) printf(MYNAME "-wpt \"%s\" (%d): Altitude = %.1f\n", - sn, wpt_class, alt); + qPrintable(res->shortname), wpt_class, alt); #endif } } #if GDB_DEBUG DBG(GDB_DBG_WPT, 1) printf(MYNAME "-wpt \"%s\": coordinates = %c%0.6f %c%0.6f\n", - sn, + qPrintable(res->shortname), res->latitude < 0 ? 'S' : 'N', res->latitude, res->longitude < 0 ? 'W' : 'E', res->longitude); #endif res->notes = fread_cstr(); #if GDB_DEBUG - DBG(GDB_DBG_WPTe, res->notes) { - char* str = gstrsub(res->notes, "\r\n", ", "); + DBG(GDB_DBG_WPTe, !res->notes.isNull()) printf(MYNAME "-wpt \"%s\" (%d): notes = %s\n", - sn, wpt_class, nice(str)); - xfree(str); - } + qPrintable(res->shortname), wpt_class, + qPrintable(QString(res->notes).replace("\r\n", ", "))); #endif if (FREAD_C == 1) { WAYPT_SET(res, proximity, FREAD_DBL); #if GDB_DEBUG DBG(GDB_DBG_WPTe, 1) printf(MYNAME "-wpt \"%s\" (%d): Proximity = %.1f\n", - sn, wpt_class, res->proximity / 1000); + qPrintable(res->shortname), wpt_class, res->proximity / 1000); #endif } i = FREAD_i32; #if GDB_DEBUG DBG(GDB_DBG_WPTe, i) printf(MYNAME "-wpt \"%s\" (%d): display = %d\n", - sn, wpt_class, i); + qPrintable(res->shortname), wpt_class, i); #endif switch (i) { /* display value */ case gt_gdb_display_mode_symbol: @@ -568,7 +528,7 @@ read_waypoint(gt_waypt_classes_e* waypt_class_out) #if GDB_DEBUG DBG(GDB_DBG_WPTe, 1) printf(MYNAME "-wpt \"%s\" (%d): Depth = %.1f\n", - sn, wpt_class, res->depth); + qPrintable(res->shortname), wpt_class, res->depth); #endif } @@ -584,11 +544,13 @@ read_waypoint(gt_waypt_classes_e* waypt_class_out) FREAD(buf, 2); } - (void) FREAD_CSTR_AS_QSTR; /* undocumented & unused string */ #if GDB_DEBUG - DBG(GDB_DBG_WPTe, temp) + QString temp = FREAD_CSTR_AS_QSTR; /* undocumented & unused string */ + DBG(GDB_DBG_WPTe, !temp.isEmpty()) printf(MYNAME "-wpt \"%s\" (%d): Unknown string = %s\n", - sn, wpt_class, nice(temp)); + qPrintable(res->shortname), wpt_class, qPrintable(temp)); +#else + (void) FREAD_CSTR_AS_QSTR; /* undocumented & unused string */ #endif QString linky = FREAD_CSTR_AS_QSTR; @@ -616,19 +578,19 @@ read_waypoint(gt_waypt_classes_e* waypt_class_out) #if GDB_DEBUG DBG(GDB_DBG_WPTe, 1) printf(MYNAME "-wpt \"%s\" (%d): url(%d) = %s\n", - sn, wpt_class, url_ct - i, qPrintable(str)); + qPrintable(res->shortname), wpt_class, url_ct - i, qPrintable(str)); #endif } } } #if GDB_DEBUG - DBG(GDB_DBG_WPTe, res->description) + DBG(GDB_DBG_WPTe, !res->description.isNull()) printf(MYNAME "-wpt \"%s\" (%d): description = %s\n", - sn, wpt_class, nice(res->description)); - DBG(GDB_DBG_WPTe, !res->url.isNull()) + qPrintable(res->shortname), wpt_class, qPrintable(res->description)); + DBG(GDB_DBG_WPTe, res->urls.HasUrlLink()) printf(MYNAME "-wpt \"%s\" (%d): url = %s\n", - sn, wpt_class, nice(qPrintable(res->url))); // FIXME: qPrintable and nice probably are fighting. + qPrintable(res->shortname), wpt_class, qPrintable(res->urls.GetUrlLink().url_)); #endif i = FREAD_i16; if (i != 0) { @@ -637,7 +599,7 @@ read_waypoint(gt_waypt_classes_e* waypt_class_out) #if GDB_DEBUG DBG(GDB_DBG_WPTe, i) printf(MYNAME "-wpt \"%s\" (%d): category = %d\n", - sn, wpt_class, i); + qPrintable(res->shortname), wpt_class, i); #endif if (FREAD_C == 1) { @@ -645,7 +607,7 @@ read_waypoint(gt_waypt_classes_e* waypt_class_out) #if GDB_DEBUG DBG(GDB_DBG_WPTe, 1) printf(MYNAME "-wpt \"%s\" (%d): temperature = %.1f\n", - sn, wpt_class, res->temperature); + qPrintable(res->shortname), wpt_class, res->temperature); #endif } @@ -677,7 +639,7 @@ read_waypoint(gt_waypt_classes_e* waypt_class_out) #if GDB_DEBUG DBG(GDB_DBG_WPTe, icon != GDB_DEF_ICON) printf(MYNAME "-wpt \"%s\" (%d): icon = \"%s\" (MapSource symbol %d)\n", - sn, wpt_class, nice(qPrintable(res->icon_descr)), icon); // FIXME: qPrintable and nice probably are fighting. + qPrintable(res->shortname), wpt_class, qPrintable(res->icon_descr), icon); #endif if ((str = GMSD_GET(cc, NULL))) { if (! GMSD_HAS(country)) { @@ -691,9 +653,6 @@ read_waypoint(gt_waypt_classes_e* waypt_class_out) GMSD_UNSET(subclass); #endif } -#if GDB_DEBUG - xfree(sn); -#endif *waypt_class_out = wpt_class; return res; } @@ -734,7 +693,7 @@ read_route() #if GDB_DEBUG DBG(GDB_DBG_RTE, 1) printf(MYNAME "-rte \"%s\": loading route with %d point(s)...\n", - nice(rte->rte_name), points); + qPrintable(rte->rte_name), points); #endif for (int i = 0; i < points; i++) { @@ -777,7 +736,7 @@ read_route() #if GDB_DEBUG DBG(GDB_DBG_RTE, links) printf(MYNAME "-rte_pt \"%s\" (%d): %d interlink step(s)\n", - nice(wpt->shortname), wpt_class, links); + qPrintable(wpt->shortname), wpt_class, links); #endif for (int j = 0; j < links; j++) { garmin_ilink_t* il_step = (garmin_ilink_t*) xmalloc(sizeof(*il_step)); @@ -809,7 +768,7 @@ read_route() #if GDB_DEBUG DBG(GDB_DBG_RTEe, 1) { printf(MYNAME "-rte_il \"%s\" (%d of %d): %c%0.6f %c%0.6f\n", - nice(wpt->shortname), j + 1, links, + qPrintable(wpt->shortname), j + 1, links, il_step->lat < 0 ? 'S' : 'N', il_step->lat, il_step->lon < 0 ? 'W' : 'E', il_step->lon); } @@ -857,7 +816,7 @@ read_route() #if GDB_DEBUG DBG(GDB_DBG_RTE, 1) printf(MYNAME "-rte_pt \"%s\": coordinates = %c%0.6f, %c%0.6f\n", - nice(wpt->shortname), + qPrintable(wpt->shortname), wpt->latitude < 0 ? 'S' : 'N', wpt->latitude, wpt->longitude < 0 ? 'W' : 'E', wpt->longitude); #endif @@ -957,9 +916,9 @@ read_track() res->rte_urls.AddUrlLink(UrlLink(FREAD_CSTR_AS_QSTR)); } #if GDB_DEBUG - DBG(GDB_DBG_TRK, !res->rte_url.isNull()) + DBG(GDB_DBG_TRK, res->rte_urls.HasUrlLink()) printf(MYNAME "-trk \"%s\": url = %s\n", - res->rte_name, qPrintable(res->rte_url)); + qPrintable(res->rte_name), qPrintable(res->rte_urls.GetUrlLink().url_)); #endif return res; } diff --git a/main.cc b/main.cc index 586a80a0c..11b1f5ca0 100644 --- a/main.cc +++ b/main.cc @@ -307,7 +307,7 @@ run(const char* prog_name) ivecs->read(); ivecs->rd_deinit(); - cet_convert_strings(global_opts.charset, nullptr, nullptr); + cet_convert_strings(global_opts.charset, nullptr); cet_convert_deinit(); did_something = true; @@ -350,7 +350,7 @@ run(const char* prog_name) route_backup(&rte_head_bak); track_backup(&trk_head_bak); - cet_convert_strings(nullptr, global_opts.charset, nullptr); + cet_convert_strings(nullptr, global_opts.charset); global_opts.verbose_status = saved_status; } @@ -541,12 +541,12 @@ run(const char* prog_name) ivecs->read(); ivecs->rd_deinit(); - cet_convert_strings(global_opts.charset, nullptr, nullptr); + cet_convert_strings(global_opts.charset, nullptr); cet_convert_deinit(); if (qargs.size() == 2 && ovecs) { cet_convert_init(ovecs->encode, 1); - cet_convert_strings(nullptr, global_opts.charset, nullptr); + cet_convert_strings(nullptr, global_opts.charset); if (ovecs->wr_init == nullptr) { fatal("Format does not support writing.\n"); @@ -570,7 +570,7 @@ run(const char* prog_name) int saved_status = global_opts.verbose_status; global_opts.verbose_status = 0; cet_convert_init(CET_CHARSET_ASCII, 1); - cet_convert_strings(nullptr, global_opts.charset, nullptr); + cet_convert_strings(nullptr, global_opts.charset); waypt_disp_all(waypt_disp); global_opts.verbose_status = saved_status; } diff --git a/route.cc b/route.cc index 78d2bc763..c5c2d6280 100644 --- a/route.cc +++ b/route.cc @@ -380,7 +380,6 @@ route_head::route_head() : rte_num(0), rte_waypt_ct(0), fs(nullptr), - cet_converted(0), // line_color(), line_width(-1), session(curr_session()) -- 2.30.2